//
//  main.m
//  对象作为方法的参数传递
//
//  Created by 郭志远 on 2023/11/24.
//

#import <Foundation/Foundation.h>
#pragma mark - qiang
@interface Gun : NSObject

{
    @public
    int _bullet;
}

-(void)shoot;

@end

@implementation Gun
-(void)shoot
{
    if (_bullet > 0) {
        NSLog(@"打了一枪%i", _bullet);
        _bullet--;
    }else{
        NSLog(@"没有子弹开不出来");
    }
    
}

@end

#pragma mark - bingaa
@interface Soldier : NSObject
{
    @public
    NSString * _name;
    double _height;
    double _weight;
}
-(void)fire:(Gun *)gun;

@end

@implementation Soldier
-(void)fire:(Gun *)gun
{
    [gun shoot];
}
@end

#pragma mark -
int main(int argc, const char * argv[]) {

    Soldier *sp = [Soldier new];
    sp->_name = @"asas";
    sp->_height = 12.2;
    sp->_weight = 21.2;
    
    Gun *gp = [Gun new];
    gp->_bullet = 10;
    [sp fire:gp];
    [sp fire:gp];
    return 0;
}
